package com.deng.eventflow.core;

import com.deng.eventflow.core.constant.NextStatus;

import java.util.Iterator;

public class TypedPullable<T> implements Pullable {
    /**
     * The actual pullable this class is wrapping
     */
    protected final Pullable m_pullable;

    public TypedPullable(Pullable p)
    {
        super();
        m_pullable = p;
    }

    @Override
    public final void remove()
    {
        // Cannot remove an event on a pullable
        throw new UnsupportedOperationException();
    }

    @Override
    public T pullSoft()
    {
        return (T) m_pullable.pullSoft();
    }

    @Override
    public T pull()
    {
        return (T) m_pullable.pull();
    }

    @Override
    @SuppressWarnings("squid:S2272") // since() pull throws the exception
    public final T next()
    {
        return pull();
    }

    @Override
    public NextStatus hasNextSoft()
    {
        return m_pullable.hasNextSoft();
    }

    @Override
    public boolean hasNext()
    {
        return m_pullable.hasNext();
    }

    @Override
    public Processor getProcessor()
    {
        return m_pullable.getProcessor();
    }

    @Override
    public int getPosition()
    {
        return m_pullable.getPosition();
    }

    @Override
    public Iterator<Object> iterator()
    {
        return this;
    }

    @Override
    public void start()
    {
        m_pullable.start();
    }

    @Override
    public void stop()
    {
        m_pullable.stop();
    }

    @Override
    public void dispose()
    {
        // Do nothing
    }
}
